package com.louis.testvalidationtwo;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;


/**
 * @author XRY
 * @date 2023年06月29日14:38
 */

//校验器
@Service
public class MyValidationOne {
    //使用原生的校验器
    @Autowired
    private Validator validator;

    public boolean testValidator(User user){
        Set<ConstraintViolation<User>> validate = validator.validate(user);
        return validate.isEmpty();
    }
}
